package com.dayuan.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dayuan.bean.Address;
import com.dayuan.dao.AddressMapper;

@Service
public class AddressService {

	@Resource
	private AddressMapper addressMapper;

	/*根据用户id查询address表*/
	public List<Address> selectAddressByUserId(Integer userId) {
	
		return addressMapper.selectAddressByUserId(userId);
	}

	/*增加寄货地址*/
	public int insertAddress(Address address) {
		return addressMapper.insertAddress(address);
	}

	/*根据id删除收货地址*/
	public int deleteAddressById(Integer id) {
		return addressMapper.deleteAddressById(id);
	}
	
	/*修改地址*/ 
	public int updateAddressById(Address address) {
		return addressMapper.updateAddressById(address);
	}
	
	/*修改状态*/ 
	public void updateAddressDefaultById(Integer id, Integer oldId) {
		//原来id状态改为2
		Address address = new Address();
		address.setId(oldId);
		address.setIs_default(2);
		addressMapper.updateAddressById(address);
		//新默认id状态改为1
		address.setId(id);
		address.setIs_default(1);
		addressMapper.updateAddressById(address);
	}
	
}
